package com.wz.translate.pattern;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.wz.translate.automaton.bean.DataBean;
import com.wz.translate.automaton.status.DATA;
import com.wz.translate.automaton.status.StatusMaps;
import com.wz.translate.util.TypeGetter;

public class DataAutomaton implements Automaton<DataBean>{
	
	@Override
	public DataBean match(String strings) {
		DataBean dataBean = new DataBean();
		Pattern pattern = Pattern.compile("\\[\\d*\\]");
		Matcher matcher = pattern.matcher(strings);
		if (matcher.matches()){
			return null;
		}
		String[] word = strings.split("\\[");
		String dataString = word[0];
		String datasize = word[1].substring(0, word[1].length()-1);
		dataBean.setSize(Integer.parseInt(datasize));
		TypeGetter<DATA> typeGetter = new TypeGetter<DATA>();
		if (!typeGetter.patternBeanType(dataString,dataBean,StatusMaps.DATA_MAP)){
			return null;
		}
		return dataBean;
	}
}
